package com.mahesh;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class Register
 */
public class Register extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private String fullname = null;
	private String email = null;
	private long mobno = 0;
	private String pwd = null;
	private String repwd = null;
	PreparedStatement ps;
	Connection conn = null;
	boolean result = false;
	boolean ex = false;

	public Register() {
		super();

	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		Users us = new Users();
		fullname = request.getParameter("fullname");
		email = request.getParameter("email");
		mobno = Long.parseLong(request.getParameter("mobileno"));
		pwd = request.getParameter("pwd");
		repwd = request.getParameter("repwd");
		System.out.println(email);
		Service serv = new Service();
	

		if (pwd.equals(repwd) && pwd != null) {

			try {

				System.out.println("first..........");
				if (serv.saveUserDetails(fullname, email, mobno, pwd)) {

					HttpSession session = request.getSession();
					session.setAttribute("username", fullname);
					System.out.println("Data are saved Successfully..!");
					serv.mailing(email, fullname);
					response.sendRedirect("RegSuccess.jsp");
				}
			} catch (Exception e) {
				e.printStackTrace();
			}

		} else {

			response.sendRedirect("Register.jsp");

		}

	}

}
